package cn.jdy.plugins.web;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cn.jdy.common.ctrl.BaseCtrl;
import cn.jdy.framework.log.BaseLog;
import cn.jdy.platform.entity.News;
import cn.jdy.platform.service.ConfService;
import cn.jdy.plugins.service.AssociationsService;
import cn.jdy.plugins.service.NewspService;
/**
 * 市局金点子
 * @author yym
 * @since 18032016
 */

@Controller
@RequestMapping("/articlelist")
public class ArticleCtrl extends BaseCtrl {
	
	@Autowired
	private NewspService newsService;
	@Autowired
	private ConfService confService;
	@Autowired
	private AssociationsService associationsService;
	
	/**
	 * 投稿文章状态为审核
	 * @param news
	 * @return
	 */
	@RequestMapping("/list/{username}.html")
	public ModelAndView queryByPage(News article,  @PathVariable String username) {
		ModelAndView mv = new ModelAndView("/article/articleList.jsp");
		try {
			//襄阳市公安局，需要加入当前时间段周数
			Date datetime = new Date();
			int weekdays = datetime.getDay();
			article.setStatus("1");        //add with daihu 控制前台页面不显示没有审核通过的数据
			article.setUsername(this.aautils(username));
			mv.addObject("weekdays",weekdays);
			
			
			// 设置分页信息
			if (article.getiDisplayLength() == 0)
				article.setiDisplayLength(24); // 默认长度24
			if (article.getPageNo() <= 0)
				article.setPageNo(1); // 默认页数1
			article.setiDisplayStart((article.getPageNo() - 1)
					* article.getiDisplayLength()); // 显示起始索引
			//mv.addObject("pageNo", 1);///
			mv.addObject("dataList",newsService.query2(article, username));
			mv.addObject("username", username);
			mv.addObject("total",newsService.count2(article, username));
			mv.addObject("iTotalRecords",newsService.count());
			mv.addObject("countnum",associationsService.autilgroup(this.aautils(username)));
			mv.addObject("pageNo", article.getPageNo());///
			mv.addObject("size", article.getiDisplayLength());
		} catch(Exception e) {
			BaseLog.e(this.getClass(), "查询异常", e);
		}
		return mv;
	}


	public String aautils(String name){
		  String namenum=null;
		  switch(name){
		  case "指挥调度科":namenum = "zhddk";break;
		  case "机要秘书科":namenum = "jymsk";break;
		  case "科技信息科":namenum = "kjxxk";break;
		  case "综合科":namenum = "zhk";break;
		  case "干部科":namenum = "gbk";break;
		  case "宣教科":namenum = "xjk";break;
		  case "老干科":namenum = "lgk";break;
		  case "培训基地":namenum = "pxjd";break;
		  case "审计监察科":namenum = "sjjck";break;
		  case "申诉控告科":namenum = "kgssk";break;
		  case "警务保障部":namenum = "jwbzb";break;
		  case "出入境管理科":namenum = "crjglk";break;
		  case "纪委":namenum = "jw";break;
		  case "机关党委":namenum = "jgdw";break;
		  case "国保支队":namenum = "gbzd";break;
		  case "反恐支队":namenum = "fkzd";break;
		  case "经侦支队":namenum = "jzzd";break;
		  case "治安内保支队":namenum = "zazd";break;
		  case "刑侦支队":namenum = "xzzd";break;
		  case "监管支队":namenum = "jgzd";break;
		  case "巡警支队":namenum = "xjzd";break;
		  case "技侦支队":namenum = "jszczd";break;
		  case "禁毒支队":namenum = "jdzd";break;
		  case "交警支队":namenum = "jjzd";break;
		  case "交警大队":namenum = "jjdd";break;
		  case "高警支队":namenum = "gsjjzd";break;
		  case "网安支队":namenum = "wazd";break;
		  case "特警支队":namenum = "tjzd";break;
		  case "法制支队":namenum = "fzzd";break;
		  case "警务督察支队":namenum = "jwdczd";break;
		  case "消防支队":namenum = "xfzd";break;
		  case "警卫处":namenum = "jwc";break;
		  case "城管公交分局":namenum = "cggjfj";break;
		  case "机场分局":namenum = "jcfj";break;
		  case "襄城分局":namenum = "xcfj";break;
		  case "樊城分局":namenum = "fcfj";break;
		  case "高新分局":namenum = "gxfj";break;
		  case "襄东分局":namenum = "xdfj";break;
		  case "东津新区分局":namenum = "djxqfj";break;
		  case "鱼梁洲分局":namenum = "ylzfj";break;
		  case "襄州区分局":namenum = "xzgafj";break;
		  case "枣阳市局":namenum = "zysgaj";break;
		  case "宜城市局":namenum = "ycsgaj";break;
		  case "老河口市局":namenum = "lhksgaj";break;
		  case "南漳县局":namenum = "nzxgaj";break;
		  case "保康县局":namenum = "bkxgaj";break;
		  case "谷城县局":namenum = "gcxgaj";break;
		  
		  case "控申科":namenum = "ksk";break;
		  case "政工室":namenum = "zgs";break;
		  case "法制大队":namenum = "fzdd";break;
		  case "警务保障室":namenum = "jwbzs";break;
		  case "网安大队":namenum = "wadd";break;
		  case "国保大队":namenum = "gbdd";break;
		  case "经侦大队":namenum = "jzdd";break;
		  case "治安大队":namenum = "zadd";break;
		  case "刑警大队":namenum = "xjdd";break;
		  case "禁毒大队":namenum = "jddd";break;
		  case "看守所":namenum = "kss";break;
		  case "拘留所":namenum = "jls";break;
		  case "城管中队":namenum = "cgzd";break;
		  case "森林公安局":namenum = "slgaj";break;
		  case "武警中队":namenum = "wjzd";break;
		  case "消防大队":namenum = "xfdd";break;
		  case "指挥中心":namenum = "zhzx";break;
		  case "秘书科":namenum = "msk";break;
		  case "鄢城派出所":namenum = "ycpcs";break;
		  case "小河派出所":namenum = "xhpcs";break;
		  case "刘猴派出所":namenum = "lhpcs";break;
		  case "雷河派出所":namenum = "lvhpcs";break;
		  case "孔湾派出所":namenum = "kwpcs";break;
		  case "郑集派出所":namenum = "zjpcs";break;
		  case "南营派出所":namenum = "nypcs";break;
		  case "王集派出所":namenum = "wjpcs";break;
		  case "板桥店派出所":namenum = "bqdpcs";break;
		  case "流水派出所":namenum = "lspcs";break;
		  case "上大堰派出所":namenum = "sdypcs";break;
		  case "东方派出所":namenum = "dfpcs";break;
		  }
		  return namenum;
	  }
	/**
	 * 投稿文章状态为未审核
	 * @param news
	 * @return
	 */
	/*
	@RequestMapping("/lists")
	public ModelAndView queryBys(News article, String fromDate, String toDate) {
		ModelAndView mv = new ModelAndView("/advice/advicemore.jsp");
		try {
			//襄阳市公安局，需要加入当前时间段周数
			Date datetime = new Date();
			int weekdays = datetime.getDay();
			mv.addObject("weekdays",weekdays);
			
			// 设置分页信息
			if (article.getiDisplayLength() == 0)
				article.setiDisplayLength(5); // 默认长度5
			if (article.getPageNo() <= 0)
				article.setPageNo(1); // 默认页数1
			article.setiDisplayStart((article.getPageNo() - 1)
					* article.getiDisplayLength()); // 显示起始索引
			article.setStatus("1");        //add with daihu 控制前台页面不显示没有审核通过的数据
			mv.addObject("dataList",newsService.query(article, fromDate, toDate));
			mv.addObject("pageNo", article.getPageNo());///
			mv.addObject("size", article.getiDisplayLength());
			mv.addObject("total",newsService.count(article, fromDate, toDate));
			mv.addObject("iTotalRecords",newsService.count());
		} catch(Exception e) {
			BaseLog.e(this.getClass(), "查询异常", e);
		}
		return mv;
	} */
}
